<template>
	<view>
		<!-- 商品轮播 -->
		<swiper class="sw_box" :indicator-dots="true" :autoplay="true" :circular="true" :interval="3000" :duration="1000">
			<swiper-item  v-for="(item, i) in goods_info.pics" :key="i">
				<view class="swiper-item">
					<image class="sw_img" :src="item.pics_big" mode="widthFix" @click="acIndex(i)"></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- 商品信息 -->
		<view class="goods_info_box">
			<!-- 价格 -->
			<view class="goods_price">
				<text>￥:{{goods_info.goods_price}}</text>
			</view>
			<!-- 标题 -->
			<view class="goods_tit">
				<text>{{goods_info.goods_name}}</text>
				<view class="icon_box">
					<u-icon class="icon" name="star" color="gray" size="28"></u-icon>
					<text>收藏</text>
				</view>
			</view>
			<!-- 运费 -->
			<view class="goods_yf">
				<text>快递：包邮</text>
			</view>
		</view>
		<!-- 商品详情 -->
		<view class="goods_detail_box">
			<rich-text :nodes="goods_info.goods_introduce"></rich-text>
		</view>
		
		
		<goods_bar @m_click="btnJoin"></goods_bar>
	</view>
</template>

<script>
	// import store from '@/store/store.js'
	import {mapState, mapMutations} from 'vuex'
	
	export default {
		computed: {
			...mapState('m_cart', ['cart'])
		},
		data() {
			return {
				goods_info: {}
			};
		},
		onLoad(options){
			console.log('options',options);
			this.getGoodsList(options)
		},
		methods: {
			...mapMutations('m_cart', ['addToCart']),
			async getGoodsList(val){
				const {data: res} = await uni.$http.get('/api/public/v1/goods/detail', val)
				this.goods_info = res.message
				console.log(this.goods_info);
			},
			// 大图预览
			acIndex(idx){
				uni.previewImage({
					current: idx,
					indicator: 'default',
					urls: this.goods_info.pics.map(item => item.pics_big)
				})
			},
			// 点击购物车功能
			btnJoin(){
				// console.log(this.goods_info);
				const goods = {
					goods_id: this.goods_info.goods_id,
					goods_name: this.goods_info.goods_name,
					goods_price: this.goods_info.goods_price,
					goods_count: 1,
					goods_small_logo: this.goods_info.goods_small_logo,
					goods_state: true
				}
				this.addToCart(goods)
			}
		}
	}
</script>

<style lang="scss">
	.sw_box{
		height: 900rpx;
		.swiper-item{
			display: block;
			width: 100%;
			height: 100%;
			position: relative;
			image{
				width:100%;
				height:100%;
				margin-top: 15%;
				// position: absolute;
				// top:50%;
				// left:50%;
				// transform:translate(-50%,-50%);
				scale: 1.3;
			}
		}
	}
	
	.goods_info_box{
		// font-size: 18px;
		padding: 20rpx 40rpx;
		.goods_price{
			margin: 20rpx 0;
			text{
				font-size: 22px;
				color: #ff3c3f;
				font-weight: bold;
			}
		}
		.goods_tit{
			display: flex;
			justify-content: space-between;
			align-items: flex-start;
			text{font-size: 16px;}
			.icon_box{
				margin-top: 5px;
				border-left: 1rpx solid gray;
				display: flex;
				flex-wrap: wrap;
				justify-content: center;
				text-align: center;
				width: 150px;
				color: gray;
				text{
					font-size: 18px;
				}
			}
		}
		.goods_yf{
			margin-top: 10px;
			text{
				color: gray;
			}
		}
	}
</style>
